package a02_链表;

/**
 * <p>
 * a02_移除链表元素复习5
 * </p>
 *
 * @author flyduck
 * @since 2024-12-29
 */
public class a02_移除链表元素复习5 {
    public ListNode removeElements(ListNode head, int val) {
        ListNode dummyNode = new ListNode(0);
        dummyNode.next = head;

        ListNode currentNode = dummyNode;
        while (currentNode.next != null) {
            if(currentNode.next.val == val){
                currentNode.next = currentNode.next.next;
            }else {
                currentNode = currentNode.next;
            }
        }
        return dummyNode.next;
    }
}
